﻿package com.toncen.samepms.basic.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.toncen.samepms.common.AbstractDomain;
import com.toncen.samepms.common.IPropertyUniqueble;
import com.toncen.samepms.common.ITreeable;
import com.toncen.samepms.common.Unique;
import com.sky.common.string.StringUtils;
import com.sky.simple.engine.IWorkflowParticipator;

/**
 * 描述：表BASIC_ORGANIZATION的domain文件
 * 
 * @author tch
 */
public class Organization extends AbstractDomain implements ITreeable, IPropertyUniqueble,IWorkflowParticipator {
	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1331527609455L;

	/**
	 * 上级组织
	 */
	private Organization parent;

	/**
	 * 名称
	 */
	@Unique(column = "NAME", title = "名称",condition="or")
	private String name;

	/**
	 * 单位类型
	 */
	private List<OrganizationType> types = new ArrayList<OrganizationType>();

	/**
	 * 组织机构代码
	 */
	@Unique(column = "ORGANIZATION_CODE", title = "组织机构代码",condition="or")
	private String organizationCode;

	/**
	 * 地址
	 */
	private String address;

	/**
	 * 电话
	 */
	private String telphone;

	/**
	 * 邮编
	 */
	private String postNumber;

	/**
	 * 传真
	 */
	private String fax;

	/**
	 * 法定代表人姓名
	 */
	private String corporationName;

	/**
	 * 法定代表人性别
	 */
	private int corporationSex = 1;

	/**
	 * 法定代表人出生日期
	 */
	private Date corporationBirthday;

	/**
	 * 法定代表人电子邮箱
	 */
	private String corporationEmail;

	/**
	 * 法定代表人电话
	 */
	private String corporationTel;

	/**
	 * 法定代表人手机
	 */
	private String corporationMobile;

	/**
	 * 负责人姓名
	 */
	private String principalName;

	/**
	 * 负责人性别
	 */
	private int principalSex = 1;

	/**
	 * 负责人出生日期
	 */
	private Date principalBirthday;

	/**
	 * 负责人电子邮箱
	 */
	private String principalEmail;

	/**
	 * 负责人电话
	 */
	private String principalTelphone;

	/**
	 * 负责人手机
	 */
	private String principalMobile;

	/**
	 * 顺序
	 */
	private int sequence = 10;

	/**
	 * 所有组织（除本身组织外）
	 */
	private List<Organization> childs = new ArrayList<Organization>();

	/**
	 * 当前组织的用户
	 */
	private List<User> users = new ArrayList<User>();

	/**
	 * @return the sequence
	 */
	public int getSequence() {
		return sequence;
	}

	/**
	 * @param sequence
	 *            the sequence to set
	 */
	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	/**
	 * @return the users
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @param users
	 *            the users to set
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @return the childs
	 */
	public List<Organization> getChilds() {
		return childs;
	}

	/**
	 * @param childs
	 *            the childs to set
	 */
	public void setChilds(List<Organization> childs) {
		this.childs = childs;
	}

	public Organization() {
		super();
	}

	/**
	 * @return the parent
	 */
	public Organization getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(Organization parent) {
		this.parent = parent;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the types
	 */
	public List<OrganizationType> getTypes() {
		return types;
	}

	/**
	 * @param types
	 *            the types to set
	 */
	public void setTypes(List<OrganizationType> types) {
		this.types = types;
	}

	/**
	 * @return
	 */
	public String[] getProxyTypes() {
		String[] proxyTypes = new String[types.size()];
		for (int i = 0; i < types.size(); i++) {
			proxyTypes[i] = String.valueOf(types.get(i).getType());
		}
		return proxyTypes;
	}

	/**
	 * @param proxyTypes
	 */
	public void setProxyTypes(String[] proxyTypes) {
		types.clear();
		if (proxyTypes != null) {
			OrganizationType type;
			for (String proxyType : proxyTypes) {
				if (!StringUtils.isEmpty(proxyType)) {
					type = new OrganizationType();
					type.setOrganization(this);
					type.setType(Integer.parseInt(proxyType));
					types.add(type);
				}
			}
		}
	}

	/**
	 * @return
	 */
	public String getProxyType() {
		String proxyType = null;
		if (types.size() != 0) {
			proxyType = String.valueOf(types.get(0).getType());
		}
		return proxyType;
	}

	/**
	 * @param proxyTypes
	 */
	public void setProxyType(String proxyType) {
		types.clear();
		if (!StringUtils.isEmpty(proxyType)) {
			OrganizationType type = new OrganizationType();
			type.setOrganization(this);
			type.setType(Integer.parseInt(proxyType));
			types.add(type);
		}
	}

	/**
	 * @return the organizationCode
	 */
	public String getOrganizationCode() {
		return organizationCode;
	}

	/**
	 * @param organizationCode
	 *            the organizationCode to set
	 */
	public void setOrganizationCode(String organizationCode) {
		this.organizationCode = organizationCode;
	}

	/**
	 * @return the address
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * @param address
	 *            the address to set
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the telphone
	 */
	public String getTelphone() {
		return telphone;
	}

	/**
	 * @param telphone
	 *            the telphone to set
	 */
	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	/**
	 * @return the postNumber
	 */
	public String getPostNumber() {
		return postNumber;
	}

	/**
	 * @param postNumber
	 *            the postNumber to set
	 */
	public void setPostNumber(String postNumber) {
		this.postNumber = postNumber;
	}

	/**
	 * @return the fax
	 */
	public String getFax() {
		return fax;
	}

	/**
	 * @param fax
	 *            the fax to set
	 */
	public void setFax(String fax) {
		this.fax = fax;
	}

	/**
	 * @return the corporationName
	 */
	public String getCorporationName() {
		return corporationName;
	}

	/**
	 * @param corporationName
	 *            the corporationName to set
	 */
	public void setCorporationName(String corporationName) {
		this.corporationName = corporationName;
	}

	/**
	 * @return the corporationSex
	 */
	public int getCorporationSex() {
		return corporationSex;
	}

	/**
	 * @param corporationSex
	 *            the corporationSex to set
	 */
	public void setCorporationSex(int corporationSex) {
		this.corporationSex = corporationSex;
	}

	/**
	 * @return the corporationBirthday
	 */
	public Date getCorporationBirthday() {
		return corporationBirthday;
	}

	/**
	 * @param corporationBirthday
	 *            the corporationBirthday to set
	 */
	public void setCorporationBirthday(Date corporationBirthday) {
		this.corporationBirthday = corporationBirthday;
	}

	/**
	 * @return the corporationEmail
	 */
	public String getCorporationEmail() {
		return corporationEmail;
	}

	/**
	 * @param corporationEmail
	 *            the corporationEmail to set
	 */
	public void setCorporationEmail(String corporationEmail) {
		this.corporationEmail = corporationEmail;
	}

	/**
	 * @return the corporationTel
	 */
	public String getCorporationTel() {
		return corporationTel;
	}

	/**
	 * @param corporationTel
	 *            the corporationTel to set
	 */
	public void setCorporationTel(String corporationTel) {
		this.corporationTel = corporationTel;
	}

	/**
	 * @return the corporationMobile
	 */
	public String getCorporationMobile() {
		return corporationMobile;
	}

	/**
	 * @param corporationMobile
	 *            the corporationMobile to set
	 */
	public void setCorporationMobile(String corporationMobile) {
		this.corporationMobile = corporationMobile;
	}

	/**
	 * @return the principalName
	 */
	public String getPrincipalName() {
		return principalName;
	}

	/**
	 * @param principalName
	 *            the principalName to set
	 */
	public void setPrincipalName(String principalName) {
		this.principalName = principalName;
	}

	/**
	 * @return the principalSex
	 */
	public int getPrincipalSex() {
		return principalSex;
	}

	/**
	 * @param principalSex
	 *            the principalSex to set
	 */
	public void setPrincipalSex(int principalSex) {
		this.principalSex = principalSex;
	}

	/**
	 * @return the principalBirthday
	 */
	public Date getPrincipalBirthday() {
		return principalBirthday;
	}

	/**
	 * @param principalBirthday
	 *            the principalBirthday to set
	 */
	public void setPrincipalBirthday(Date principalBirthday) {
		this.principalBirthday = principalBirthday;
	}

	/**
	 * @return the principalEmail
	 */
	public String getPrincipalEmail() {
		return principalEmail;
	}

	/**
	 * @param principalEmail
	 *            the principalEmail to set
	 */
	public void setPrincipalEmail(String principalEmail) {
		this.principalEmail = principalEmail;
	}

	/**
	 * @return the principalTelphone
	 */
	public String getPrincipalTelphone() {
		return principalTelphone;
	}

	/**
	 * @param principalTelphone
	 *            the principalTelphone to set
	 */
	public void setPrincipalTelphone(String principalTelphone) {
		this.principalTelphone = principalTelphone;
	}

	/**
	 * @return the principalMobile
	 */
	public String getPrincipalMobile() {
		return principalMobile;
	}

	/**
	 * @param principalMobile
	 *            the principalMobile to set
	 */
	public void setPrincipalMobile(String principalMobile) {
		this.principalMobile = principalMobile;
	}

	/**
	 * 获取级联下级组织
	 * 
	 * @return
	 */
	public List<Organization> getCascadeChilds() {
		List<Organization> cascadeChilds = new ArrayList<Organization>();
		cascadeChilds.addAll(getChilds());// 添加当前下级组织
		for (Organization child : getChilds()) {
			cascadeChilds.addAll(child.getCascadeChilds());// 添加当前下下级组织
		}
		return cascadeChilds;
	}

	/**
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<ITreeable> getTreeChild() throws Exception {
		return (List) this.getChilds();
	}

	/**
	 * @return
	 * @throws Exception
	 */
	public String getTreeId() throws Exception {
		return String.valueOf(this.getId());
	}

	/**
	 * @return
	 * @throws Exception
	 */
	public String getTreeText() throws Exception {
		return this.getName();
	}

	public String getPrimaryName() {
		return "ID";
	}

	public String getTableName() {
		return "BASIC_ORGANIZATION";
	}
}
